<?php
namespace Models;
/**
 *
 * @author buddha 
 */

class Forum extends Base {

    public function getForum()
    {
        return $this->db->query("
            SELECT fora.id as id,
                   fora.kdy as kdy,
                   fora.od as kdo,
                   fora.komu as komu_id,
                   forb.od as komu,
                   forb.text as reakce_na,
                   fora.klic as klic,
                   fora.text as text,
                   fora.email as email
            FROM pov_forum fora
            LEFT JOIN pov_forum forb ON(fora.komu=forb.id)
            WHERE fora.ok= '0' AND fora.klic=''
            ORDER BY fora.kdy DESC
            LIMIT 200
                                ");

    }
    public function getReForum($komuId)
    {
        return $this->db->query("
            SELECT fora.id as id,
                   fora.kdy as kdy,
                   fora.od as kdo,
                   fora.komu as komu,
                   fora.text as text,
                   fora.email as email,
                   fora.ok as ok
            FROM pov_forum fora
            WHERE fora.id='$komuId' OR fora.komu='$komuId'
            ORDER BY fora.kdy DESC
            LIMIT 10
                                ");

    }
    
    public function addForum($od, $komu, $text, $klic, $email, $ok)
    {   $datum = new \DibiDateTime();
       \Nette\Diagnostics\Debugger::dump($datum);
        return $this->db->query("
                INSERT INTO pov_forum (kdy, od, komu, text, klic, email, ok) VALUES (%t, %s, %i, %s, %s, %s, %i)", $datum, $od, $komu, $text, $klic, $email, $ok
                                );

    }
}